﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Learning.ConwaysGameOfLife
{
    public class CordinateEnumerator : IEnumerator<Cordinate>, IEnumerable<Cordinate>
    {
        #region Fields (1) 

        IEnumerator<Cordinate> enumerator;

        #endregion Fields 

        #region Constructors (1) 

        public CordinateEnumerator(int size)
        {
            var cordinates = new List<Cordinate>(size * size);

            for (int row = 0; row < size; row++)
            {
                for (int column = 0; column < size; column++)
                {
                    cordinates.Add(new Cordinate(row, column));
                }
            }

            this.Cordinates = cordinates;
        }

        #endregion Constructors 

        #region Properties (3) 

        private IList<Cordinate> Cordinates { get; set; }

        public Cordinate Current
        {
            get 
            {
                return this.enumerator.Current;
            }
        }

        object System.Collections.IEnumerator.Current
        {
            get 
            {
                return this.Current;
            }
        }

        #endregion Properties 

        #region Methods (6) 

        // Public Methods (5) 

        public void Dispose()
        {
            this.Cordinates = null;
        }

        public IEnumerator<Cordinate> GetEnumerator()
        {
            enumerator = this.Cordinates.GetEnumerator();
            return enumerator;
        }

        public static CordinateEnumerator CreateCordinateEnumeratorForSize(int size)
        {
            return new CordinateEnumerator(size);
        }

        public bool MoveNext()
        {
            return this.enumerator.MoveNext();
       }

         public void Reset()
        {
            this.enumerator.Reset();
        }
        // Private Methods (1) 

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        #endregion Methods 
    }
}
